package com.runssnail.juhe.api.request.mobile;

import com.runssnail.juhe.api.constants.Constants;
import com.runssnail.juhe.api.internal.utils.MD5Util;
import com.runssnail.juhe.api.request.GetRequest;
import com.runssnail.juhe.api.response.mobile.FlowRechargeResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * 流量充值请求
 *
 * Created by zhengwei on 16/4/15.
 */
public class FlowRechargeRequest extends GetRequest<FlowRechargeResponse> {

    /**
     * 手机号
     */
    private String phone;

    /**
     * 商家订单号，8-32位字母数字组合
     */
    private String orderId;

    /**
     * open id
     */
    private String pId;

    private String appKey;

    /**
     * open id
     */
    private String openId;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getpId() {
        return pId;
    }

    public void setpId(String pId) {
        this.pId = pId;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    @Override
    public String getApiUrl() {
        return "http://v.juhe.cn/flow/recharge";
    }

    @Override
    public Map<String, Object> getParams() {

//        名称	类型	必填	说明
//        phone	string	是	需要充值流量的手机号码
//        pid	string	是	流量套餐ID
//        orderid	string	是	自定义订单号，8-32字母数字组合
//        key	string	是	应用APPKEY(应用详细页查询)
//                sign	string	是	校验值，md5(OpenID+key+phone+pid+orderid)，结果转为小写
//
        Map<String, Object> params = new HashMap<>();
        params.put("orderid", this.orderId);
        params.put("phone", this.phone);
        params.put("pid", this.pId);

        String signStr = this.openId + this.appKey + this.phone + this.pId + this.orderId;

        String sign = MD5Util.MD5Encode(signStr, Constants.DEFAULT_ENCODING).toLowerCase();

        params.put("sign", sign);

        return params;
    }

    @Override
    public Class<FlowRechargeResponse> getResponseClass() {
        return null;
    }
}
